<?php

namespace Home\Model;
use Think\Model;
class LogModel extends Model {
    public function check_auth($id,$table){
        $model = M($table);
        $res = $model->field('uid')->find($id);
        $uid = $_SESSION['qzone']['home']['id'];

        if($res['uid'] && $res['uid']==$uid){
            return true;
        } else {
            return false;
        }
    }
    public function com_auth($id){
        $model = M('Log');
        $com_model = M('Log_comment');
        $res1 = $com_model->field('who_id,uid')->find($id);
        $res2 = $model->field('uid')->find($res1['who_id']);
        $uid = $_SESSION['qzone']['home']['id'];

        if($res1['uid']==$uid || $res2['uid']==$uid){
            return true;
        } else {
            return false;
        }
    }
    public function com_hf_auth($id){
        $model = M('Log');
        $com_model = M('Log_comment');
        $com_hf_model = M('Log_comment_huif');
        $res1 = $com_hf_model->field('com_id,uid')->find($id);
        $res2 = $com_model->field('who_id,uid')->find($res1['com_id']);
        $res3 = $model->field('uid')->find($res2['who_id']);
        $uid = $_SESSION['qzone']['home']['id'];

        if($res1['uid']==$uid || $res2['uid']==$uid || $res3['uid']==$uid){
            return true;
        } else {
            return false;
        }
    }

    public function getComNum($log_id){
        $com_model = M('log_comment');
        $filter = array('who_id'=>$log_id);
        $num = $com_model->where($filter)->count();

        return $num;
    }

    public function getGoodNum($log_id){
        $good_model = M('log_good');
        $filter = array('log_id'=>$log_id);
        $num = $good_model->where($filter)->count();

        return $num;
    }
}